import re
import reprlib

RE_WORD = re.compile('\w+')


class Sentence:
    def __init__(self, text):
        self.text = text
        self.words = RE_WORD.findall(text)

    def __getitem__(self, index):
        return self.words[index]

    def __len__(self):
        return len(self.words)

    def __repr__(self):
        return 'Sentence(%s)' % reprlib.repr(self.text)


if __name__ == '__main__':
    s = Sentence('"The time has come," the Walrus said,')
    for word in s:
        print(word)
    # Sentence('"The time has come," the Walrus said,')
    print(s[0])
    # 'The'
    print(s[1])
    # 'time'
    print(s[-1])
    # 'Walrus'
    print(s[1:4])
    # ['time', 'has', 'come']
    print(s[:3])
    # ['The', 'time', 'has']
    print(s[1:-1])
    # ['time', 'has', 'come', ',', 'the', 'Walrus']
    print(s[4:])
    # ['has', 'come', ',', 'the', 'Walrus']
    print(s[4:100])
    print(s)
